using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace MontandoCenario
{
  
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        int[,] mapa;
        int larguraTile;
        int alturaTile;
        Texture2D imagemMapa;
        Vector2 posicaoInicialXY;


        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            graphics.PreferredBackBufferWidth = 490;
            graphics.PreferredBackBufferHeight = 490;

        }

        protected override void Initialize()
        {
            larguraTile = 49;
            alturaTile = 49;


            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            spriteBatch = new SpriteBatch(GraphicsDevice);
            imagemMapa = Content.Load<Texture2D>("cenario");
            carregaMapa();


        }

        /// <summary>
        /// Mapa dos tiles
        /// </summary>
        private void carregaMapa()
        {
            mapa = new int[,]{
                                {1,1,1,0,1,1,1,1,1,1},
                                {1,0,1,1,1,0,1,1,0,1},
                                {1,2,1,0,1,1,1,1,1,1},
                                {1,1,1,1,1,1,0,1,1,1},
                                {1,1,1,0,2,1,1,0,1,1},
                                {1,1,1,1,1,1,1,1,1,1},
                                {1,1,1,1,1,1,1,2,1,1},
                                {1,1,1,1,2,1,0,1,1,1},
                                {1,1,1,0,1,1,1,1,1,1},
                                {1,1,1,1,1,1,1,1,1,1}                         
                            };
        }

      
        protected override void UnloadContent()
        {
            
        }

       
        protected override void Update(GameTime gameTime)
        {
          

            base.Update(gameTime);
        }

       
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();

            for (int linha = 0; linha < 10; linha++)
            {
                for (int coluna = 0; coluna < 10; coluna++)
                {
                    posicaoInicialXY = new Vector2(coluna * larguraTile,
                                                    linha * alturaTile);
                    spriteBatch.Draw(imagemMapa, posicaoInicialXY,
                                     new Rectangle(mapa[linha, coluna] * larguraTile,
                                                   0, larguraTile, alturaTile),
                                     Color.White);
                }
            }

            spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
